%% This File Constructs the Descriptive Data Figures %%

% When using this code or parts of it, please cite Paul, Pascal. 2019. 
% "The Time-Varying Effect of Monetary Policy on Asset Prices". 
% Review of Economics & Statistics.

clear all
clc

%% Choose Sample & Coloring of Figures

start_year  = 1988;
start_month = 11;
end_year    = 2017;
end_month   = 9;

colored_figures = 1;

%% Load Data

cd '..\Data\Macro Time Series'

% Load Macro series (1960 M1 - 2017 M9)
macro           = xlsread('Macro Data.xls','Data','C2:H694');
% Convert stock prices, dividends, and house prices to real units
macro(:,2)      = 100*macro(:,2)./macro(:,5);
macro(:,3)      = 100*macro(:,3)./macro(:,5);
macro(:,4)      = 100*macro(:,4)./macro(:,5);

cd '..\Monetary Policy Surprises'

% Load Monetary Policy Surprises
surprises       = xlsread('Monetary_Surprises.xls','Scheduled_Meetings','C2:C405');

cd '..\..\Data Description Figures'

%% Define Variables

vars            = [macro(:,1), macro(:,2), macro(:,3), macro(:,4), macro(:,5), macro(:,6)];
labels          = {'Federal Funds Rate','Stock Prices','Dividends','House Prices','Consumer Price Index','Indutrial Production'};
taking_logs     = [0, 1, 1, 1, 1, 1];
differencing    = [0, 1, 1, 1, 1, 1];
n_vars          = size(vars,2);

start_sample    = 12*(start_year-1960)+start_month;
end_sample      = size(vars,1)-12*(2017-end_year)-(9-end_month);
vars_logs       = vars(start_sample:end_sample,:);
vars_diff       = vars_logs;

for jj = 1:size(vars_logs,2)
    if taking_logs(1,jj) == 1
        vars_logs(:,jj) = log(vars_logs(:,jj));
    end
    if differencing(1,jj) == 1
        vars_diff(:,jj)    = [0;100*diff(vars_logs(:,jj))];
    end
end

vars_diff = vars_diff(2:end,:);

% Instrument on chosen sample
start_instr     = 12*(start_year-1984) + (start_month-1);
end_instr       = size(surprises,1) - 12*(2017-end_year) - (9-end_month);
instr           = surprises(start_instr:end_instr,1);

if colored_figures == 1
    line_color   = 'Mediumblue';
else
    line_color   = 'Black';
end

%% Figure 1: Monetary Policy Surprises

figure(1)
plot(instr*100,'LineWidth',3,'Color',rgb(line_color))
if start_year == 1995
    set(gca,'XTick',[1:60:size(instr,1)])
    set(gca,'XTickLabel',['1995';'2000';'2005';'2010';'2015'])
else
    set(gca,'XTick',[15:60:size(instr,1)])
    set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
end
xlim([1 size(instr,1)])
set(gca,'Box','off')
set(gca,'FontSize',28)
ylabel('Basis Points','Fontsize',34,'FontName','Palatino','Interpreter','Latex')

h = gcf;
set(h, 'PaperPositionMode','auto')
set(h,'PaperOrientation','landscape')
set(h,'Position',[0 0 1800 1000])
tightfig
print(h,'-depsc','..\Output\Figure_1')

%% Figure 6: Data in log-levels

figure(6)
subplot(3,2,1)
plot(vars_logs(:,1),'LineWidth',2.5,'Color',rgb(line_color))
set(gca,'XTick',[15:60:size(vars_logs,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
xlim([1 size(vars_logs,1)])
set(gca,'Box','off');
set(gca,'FontSize',16);
t= title('Federal Funds Rate (\%)');
set(gca,'Box','off')
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

subplot(3,2,2)
plot(vars_logs(:,2),'LineWidth',2.5,'Color',rgb(line_color))
xlim([1 size(vars_logs,1)])
set(gca,'XTick',[15:60:size(vars_logs,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
set(gca,'Box','off');
set(gca,'FontSize',16);
t= title('log(real S\&P 500)');
set(gca,'Box','off')
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

subplot(3,2,3)
plot(vars_logs(:,3),'LineWidth',2.5,'Color',rgb(line_color))
xlim([1 size(vars_logs,1)])
set(gca,'XTick',[15:60:size(vars_logs,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
set(gca,'Box','off');
set(gca,'FontSize',16);
t= title('log(real Dividends S\&P 500)');
set(gca,'Box','off')
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

subplot(3,2,4)
plot(vars_logs(:,4),'LineWidth',2.5,'Color',rgb(line_color))
xlim([1 size(vars_logs,1)])
set(gca,'XTick',[15:60:size(vars_logs,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
set(gca,'Box','off');
set(gca,'FontSize',16);
t= title('log(real S\&P-CS Home Price Index)');
set(gca,'Box','off')
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

subplot(3,2,5)
plot(vars_logs(:,5),'LineWidth',2.5,'Color',rgb(line_color))
xlim([1 size(vars_logs,1)])
set(gca,'XTick',[15:60:size(vars_logs,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
set(gca,'Box','off');
set(gca,'FontSize',16);
t= title('log(Consumer Price Index)');
set(gca,'Box','off')
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

subplot(3,2,6)
plot(vars_logs(:,6),'LineWidth',2.5,'Color',rgb(line_color))
xlim([1 size(vars_logs,1)])
set(gca,'XTick',[15:60:size(vars_logs,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
set(gca,'Box','off');
set(gca,'FontSize',16);
t= title('log(real Industrial Production)');
set(gca,'Box','off')
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

h = gcf;
set(h, 'PaperPositionMode','auto')
set(h,'PaperOrientation','landscape')
set(h,'Position',[0 0 1500 1000])
tightfig
print(h,'-depsc','..\Output\Figure_6')

%% Figure 7: Data in first differences
    
figure(7)
subplot(3,2,1)
plot(vars_diff(:,1),'LineWidth',2.5,'Color',rgb(line_color))
set(gca,'XTick',[14:60:size(vars_diff,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
xlim([1 size(vars_diff,1)])
set(gca,'Box','off');
set(gca,'FontSize',16);
t= title('Federal Funds Rate (\%)');
set(gca,'Box','off')
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

subplot(3,2,2)
plot(vars_diff(:,2),'LineWidth',2.5,'Color',rgb(line_color))
xlim([1 size(vars_diff,1)])
set(gca,'XTick',[14:60:size(vars_diff,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
set(gca,'Box','off');
set(gca,'FontSize',16);
t= title('$\Delta$log(real S\&P 500)*100','Interpreter','Latex');
set(gca,'Box','off')
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

subplot(3,2,3)
plot(vars_diff(:,3),'LineWidth',2.5,'Color',rgb(line_color))
xlim([1 size(vars_diff,1)])
set(gca,'XTick',[14:60:size(vars_diff,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
set(gca,'Box','off');
set(gca,'FontSize',16);
t= title('$\Delta$log(real Dividends S\&P 500)*100','Interpreter','Latex');
set(gca,'Box','off')
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

subplot(3,2,4)
plot(vars_diff(:,4),'LineWidth',2.5,'Color',rgb(line_color))
xlim([1 size(vars_diff,1)])
set(gca,'XTick',[14:60:size(vars_diff,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
set(gca,'Box','off');
set(gca,'FontSize',16);
t= title('$\Delta$log(real S\&P-CS Home Price Index)*100','Interpreter','Latex');
set(gca,'Box','off')
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

subplot(3,2,5)
plot(vars_diff(:,5),'LineWidth',2.5,'Color',rgb(line_color))
xlim([1 size(vars_diff,1)])
set(gca,'XTick',[14:60:size(vars_diff,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
t= title('$\Delta$log(Consumer Price Index)*100','Interpreter','Latex');
set(gca,'Box','off')
set(gca,'FontSize',16);
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

subplot(3,2,6)
plot(vars_diff(:,6),'LineWidth',2.5,'Color',rgb(line_color))
xlim([1 size(vars_diff,1)])
set(gca,'XTick',[14:60:size(vars_diff,1)])
set(gca,'XTickLabel',['1990';'1995';'2000';'2005';'2010';'2015'])
set(gca,'Box','off');
set(gca,'FontSize',16);
t= title('$\Delta$log(real Industrial Production)*100','Interpreter','Latex');
set(t,'fontsize',20,'FontName','Palatino','Interpreter','Latex')

h = gcf;
set(h, 'PaperPositionMode','auto')
set(h,'PaperOrientation','landscape')
set(h,'Position',[0 0 1500 1000])
tightfig
print(h,'-depsc','..\Output\Figure_7')
